/*
 * 11.4.cpp
 *
 *  Created on: 2012-5-25
 *      Author: jawinton
 */


#include <cstdio>
#include <algorithm>

using namespace std;

struct Monkey{
	int ID;
	Monkey *next;
};

struct MonkeyList{
	Monkey *head, *tail;
	int totalMonkey;
};

MonkeyList list;

bool addMonkey(Monkey *m) {
	if (list.tail == NULL) {
		list.head = list.tail = m;
		m->next = list.head;
	} else {
		m->next = list.tail->next;
		list.tail->next = m;
		list.tail = m;
	}
	list.totalMonkey++;
	return true;
}

bool delMonkeyNext(Monkey *m) {
	if (list.totalMonkey == 0) return false;
	Monkey *tmp = m->next;
	m->next = m->next->next;
	delete tmp;
	list.totalMonkey--;
	return true;
}

int main (void) {
	int n, m;
	while (true) {
		scanf("%d%d", &n, &m);
		if (n == 0) break;
		list.head = list.tail = NULL;
		list.totalMonkey = 0;
		Monkey *monkey;
		for (int i=0; i<n; i++) {
			monkey = new Monkey;
			monkey->ID = i+1;
			addMonkey(monkey);
		}
		Monkey *node = list.tail;
		while (list.totalMonkey > 1) {
			for (int i=1; i<m; i++) {
				node = node->next;
			}
			delMonkeyNext(node);
		}
		printf("%d\n", node->ID);
	}
	return 0;
}
